import time

from re_common.baselibrary.utils.basedir import BaseDir

from re_common.baselibrary.utils.basepymongo import BasePyMongo


now_date = time.strftime('%Y%m%d', time.localtime())
file_path = r'E:\download\paper\{}'.format(now_date)
BaseDir.create_dir(file_path)
txt_path = file_path + '/' + now_date + "_count" + '.txt'


insertmongo = BasePyMongo("mongodb://cjrw:vipdatacenter@192.168.31.243:32920,192.168.31.206:32920,192.168.31.208:32920/?authSource=htmljsonlatest")
insertmongo.use_db("htmljsonlatest")
insertmongo.create_col("a_paper_latest")

for journal_name in ['北京日报', '解放军报', '经济日报', '人民日报', '人民日报海外版', '学习时报', '光明日报', '法制日报', '文汇报', '新华每日电讯', '新华日报',
                     '中国国防报', '中国青年报', '中国教育报', '中国能源报', '农民日报', '科技日报', '中国科学报', '工人日报']:
    print(journal_name)
    paper_count = insertmongo.find({"journal_name": journal_name}).count()
    paper_count_txt = journal_name + ":" + str(paper_count) + "\n"
    with open(txt_path, mode="a", encoding="utf-8") as f:
        f.write(paper_count_txt)
        f.close()
